#ifndef _AD_CONSTRUCT_H_
#define _AD_CONSTRUCT_H_

#include "grate_constants.h"
#include "words_queue.h"
#include "dfa.h"
#include "input_data.h"
#include "grate_config.h"

// Main function, called to construct the AD using WORDS_QUEUE, and store AD in the trie DFA
// Returns the maximal number of symbols that were present in the queue at one moment
i64 construct_antidictionary(grate_config & CONFIG, input_data & INPUT, words_queue * WORDS_QUEUE, dfa * DFA);

// Checks if the words with root of length len cannot occur in the antidictionary
const bool bad_length(const int len, const int alh_size);

// Returns the miminal length of forbidden word where plen is the length of its root
inline int get_length(int plen, input_data & INPUT);

// Hadles root stored in cword and adds forbidden word constructed from it if necessary
// Returns the length of first bad prefix
// If trie_enough is true, uses only forbidden function, otherwise make dumb check
int handle_root(const char* cword, int clen, bool trie_enough, dfa * DFA, input_data & INPUT);

// Check all prefixes of cword starting from cword[0..slen] to cword[0..clen-1]
// Checks only root lengths for which there are no words in AD
// Returns the number of the first prefix which is bad
int has_bad_prefix_dumb(const char* cword, int clen, int slen, input_data & INPUT);

void run_dfs(char * cword, int clen, char maxlet, input_data & INPUT);

#endif